#include <iostream>

int strstr(const std::string haystack, const std::string needle)
{
    int i = 0;
    while (i < haystack.size())
    {
        bool is_match = true;
        int k = i;
        int j = 0;
        while (k < haystack.size() && j < needle.size())
        {
            if (needle[j] == '[')
            {
                while (j < needle.size() && needle[j] != ']')
                {
                    if (haystack[k] == needle[j])
                    {
                        is_match = true;
                        break;
                    }
                    k++;
                }
                if (is_match)
                {
                    while (needle[j] != ']')
                    {
                        j++;
                    }
                }
                else
                {
                    is_match = false;
                    break;
                }

                k++;
                j++;
            }
            else
            {
                if (needle[j] == haystack[k])
                {
                    is_match = true;
                    k++;
                    j++;
                }
                else
                {
                    is_match = false;
                    break;
                }
            }
        }
        if (is_match)
        {
            return i;
        }
        i++;
    }

    return -1;
}

int main()
{
    std::string haystack;
    std::cin >> haystack;
    std::string needle;
    std::cin >> needle;

    int ret = strstr(haystack, needle);
    std::cout << ret << std::endl;

    return 0;
}